package com.server.llh.llhserverwork.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.bean.FoodOrderInfosBean;

import java.util.List;

/**
 * Created by ZTF on 2017-06-15.
 */

public class OrderInfoAdapter extends BaseAdapter {
    Context context;
    List<FoodOrderInfosBean.DataBean.WapDietInfoListBean> wapDietInfoListBeen;
    public OrderInfoAdapter(Context context,  List<FoodOrderInfosBean.DataBean.WapDietInfoListBean> wapDietInfoListBeen){
        this.wapDietInfoListBeen=wapDietInfoListBeen;
        this.context=context;
    }
    @Override
    public int getCount() {
        if (wapDietInfoListBeen==null&&wapDietInfoListBeen.size()==0){
            return 0;
        }
        return wapDietInfoListBeen.size();
    }

    @Override
    public Object getItem(int position) {
        return wapDietInfoListBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HolderView holderView=null;
        if (convertView==null){
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.llh_f_order_item, null);
            holderView=new HolderView();
            holderView. downOrderTime = (TextView) convertView.findViewById(R.id.down_order_time);
            holderView. orderProName = (TextView) convertView.findViewById(R.id.order_pro_name);
            holderView. orderProNum = (TextView) convertView.findViewById(R.id.order_pro_num);
            holderView. orderProPrice = (TextView) convertView.findViewById(R.id.order_pro_price);

            convertView.setTag(holderView);
        } else {
            holderView = (HolderView) convertView.getTag();
        }
        FoodOrderInfosBean.DataBean.WapDietInfoListBean wapDietInfoListBean=wapDietInfoListBeen.get(position);

        if (!TextUtils.isEmpty(wapDietInfoListBean.getProName())&&wapDietInfoListBean.getMealTime()==1){
            holderView. downOrderTime.setText(""+wapDietInfoListBean.getAddTime()+"早餐");
        }else if (!TextUtils.isEmpty(wapDietInfoListBean.getProName())&&wapDietInfoListBean.getMealTime()==2){
            holderView. downOrderTime.setText(""+wapDietInfoListBean.getAddTime()+"午餐");
        }else if (!TextUtils.isEmpty(wapDietInfoListBean.getProName())&&wapDietInfoListBean.getMealTime()==3){
            holderView. downOrderTime.setText(""+wapDietInfoListBean.getAddTime()+"晚餐");
        }else{
            holderView. downOrderTime.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(wapDietInfoListBean.getProName())) {
            holderView. orderProName.setText(""+wapDietInfoListBean.getProName());
        }else{
            holderView. orderProName.setText("快递费");
        }
        holderView. orderProNum.setText("X"+wapDietInfoListBean.getProNum());
        holderView. orderProPrice.setText("¥"+wapDietInfoListBean.getProPrice());
        return convertView;
    }
    class HolderView {
        TextView downOrderTime;
        TextView orderProName;
        TextView orderProNum;
        TextView orderProPrice;
    }
}